<%@taglib prefix="s" uri="/struts-tags"%>
<% 	String descargarFile=(String)request.getAttribute("descargarFile").toString(); 
	String messageDescarga=(String)request.getAttribute("messageDecarga").toString();
%>
<%@page import="pe.com.bbva.util.Constantes"%>
<s:form id="consultaConPagoPBPHistorialForm" theme="simple">
	<s:hidden name="idReporteControl" />
	<table width="100%">
		<tr>
			<td>
				<div id="pageTitle">Pagos PBP BBVA - Pagos PBP FMV Hist&oacute;rico</div></td>
		</tr>
		<tr>
			<td>
				<div class="formpanel">
				<fieldset class="fontfieldset">
			    <legend class="fontlegend">Resultados del Cruce de Informacion</legend>
					<table width="100%" >
						<tr>
							<td width="80%">&nbsp;</td>
							<td width="20%">
								<table width="100%">
									<tr>
										<td class="label" align="left" >Mes:</td>
										<td>
											<s:select
											list="listaMeses" listKey="value" listValue="label"  theme="simple"
											id="cMes"
											onchange="cargarHistoricoConPagoPBPHistorial()" 
											name="mesConPagoPBP" /> 
										</td>
										<td class="label" align="left" >A&ntilde;o:</td>
										<td>
										<s:textfield theme="simple" id="spinner"
											size="4"
											onchange="cargarHistoricoConPagoPBPHistorial()"
											name="anioConPagoPBP"/>
										</td>
										<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
									</tr>
								</table>
							</td>
						</tr>
					</table>
					<table width="100%">
						<tr>
							<td>&nbsp;
							<s:submit value="Exportar a Excel" id="btnExcel" disabled="habilitaBotonGenRep"
									cssClass="ui-button ui-widget ui-state-default ui-corner-all"
									action="generarExcelConPagoPBPHistorial" />&nbsp; 
	  						<s:submit value="Actualizar Formulario" disabled="habilitaBotonActualizar" 
	  								id="bActFormulario" action="actualizarConPagoPBPHistorial" 
	  								theme="simple" cssClass="ui-button ui-widget ui-state-default ui-corner-all"/>&nbsp;
										&nbsp;&nbsp;
										<% if(descargarFile.equals(Constantes.REP_TERMINO)){%>
										<img src="images/xls.png" alt="download" border="0" />
										<a href="javascript:descargarExcel();">
												<%=messageDescarga%>
							</a>
										<% } %>
							</td>
						</tr>
						<tr>
							<td>&nbsp;</td>
						</tr>
						<tr>
							<td>
								<table>
									<tr>
										<td>
											<div>
												<table id="dataTableDetalle" width="100%"></table>
												<div id="tablePagerDetalle"></div>
											</div>
										</td>
									</tr>
								</table>
							</td>
						</tr>
					</table>
					</fieldset>
					</div>
				</td>
		</tr>
	</table>
</s:form>

<script language="JavaScript" type="text/javascript">
	$(document).ready(function() {
		$('#spinner').spinner({ min: 2000, max: 2030, allowNull: false });
		jQuery("#dataTableDetalle").jqGrid({
	   	url:'./findDetalleConPagoPBPHistorial.do',
		datatype: "json",
		colNames:['ID','Oficina','Credito','Codigo Banco','Nombre','Cuota TC','Moneda','BBVA','FMV','Diferencia','BBVA','FMV','Diferencia','BBVA','FMV','Diferencia'],
	   	colModel:[
		   	{name:'idConPagoPBP',index:'idConPagoPBP',hidden:true},
		   	{name:'nroOfiPropi',index:'nroOfiPropi',width:160,align:"left"},
		   	{name:'credito',index:'credito',width:130,align:"left"},
		   	{name:'codigoBanco',index:'codigoBanco',width:130,align:"left"},
		   	{name:'nombre',index:'nombre',width:220,align:"left"},
		   	{name:'cuotaTcCofide',index:'cuotaTcCofide',width:100,align:"right"},
		   	{name:'moneda',index:'moneda',width:100,align:"left"},
		   	{name:'capitalBBVA',index:'capitalBBVA',width:50,align:"right"},
		   	{name:'capitalCofide',index:'capitalCofide',width:50,align:"right"},
		   	{name:'difCapital',index:'difCapital',width:70,align:"right",formatter:formatColorRed},
		   	{name:'interesBBVA',index:'interesBBVA',width:50,align:"right"},
		   	{name:'interesCofide',index:'interesCofide',width:50,align:"right"},
		   	{name:'difInteres',index:'difInteres',width:70,align:"right",formatter:formatColorRed},
		   	{name:'montoBBVA',index:'montoBBVA',width:50,align:"right"},
		   	{name:'montoCofide',index:'montoCofide',width:50,align:"right"},
		   	{name:'difMonto',index:'difMonto',width:70,align:"right",formatter:formatColorRed}
	   	],
	   	rowNum:50,
	   	altRows : true,
		altclass : 'myAltRowClass',
	   	rowList:[50,100,500],
	   	pager: '#tablePagerDetalle',
	   	sortname: 'idConPagoPBP',
	    viewrecords: true,
	    sortorder: "desc",
		shrinkToFit : false,
		width: 900,
	    jsonReader : {
	      root:"dataModel",
	      repeatitems: false  
	   },
	   	beforeRequest: function(){
	   		var _page=$(this).jqGrid('getGridParam', 'page');
	   		
	   		if(_page!=1){        
				var _url=$(this).jqGrid('getGridParam', 'url');
				var _idx=_url.indexOf('?');
				
		 		$(this).jqGrid('setGridParam',{url:_url,page:_page});
			}
	  }
	});
	jQuery("#dataTableDetalle").jqGrid('setGroupHeaders', {
	  useColSpanStyle: false, 
	  groupHeaders:[
  		{startColumnName: 'nroOfiPropi', numberOfColumns: 6, titleText: ' '},
		{startColumnName: 'capitalBBVA', numberOfColumns: 3, titleText: 'Principal'},
		{startColumnName: 'interesBBVA', numberOfColumns: 3, titleText: 'Interes'},
		{startColumnName: 'montoBBVA', numberOfColumns: 3, titleText: 'Monto'}
		]
	});  
	});
			
	function descargarExcel(){		
		document.forms[0].action='downloadReporteConPagoPBPHistorial.do';
		document.forms[0].submit();			
	}
	
	function cargarHistoricoConPagoPBPHistorial(){
		//alert('entro');
		$("#consultaConPagoPBPHistorialForm").attr("action","./cargarHistoricoConPagoPBPHistorial.do");
		$("#consultaConPagoPBPHistorialForm").submit();
	}
</script>